package LeetCode;

//
// Created by ✎﹏ℳ๓独赏☆独醉 on 2024/6/12.
//
//https://leetcode.cn/problems/excel-sheet-column-number/description/
public class Excel表列序号 {
    public static void main(String[] args) {
        System.out.println(titleToNumber("FXSHRXW"));
        System.out.println(titleToNumber("A"));
        System.out.println(titleToNumber("AB"));
        System.out.println(titleToNumber("ZY"));
    }
    public static int titleToNumber(String columnTitle) {
        int res = 0;
        for (int i = columnTitle.length() - 1; i >=  0; i--) {
            res = (columnTitle.charAt(i) + 1 - 'A') *(int) Math.pow(26,columnTitle.length() - 1 - i) + res;
        }
        return res;
    }
}
